package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Photo;
import com.miku.blog.domain.dto.PhotoAddDTO;
import com.miku.blog.domain.param.ReceptionParam;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.PhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-06-14 0:51
 */
@Api(tags = "后台管理系统{相册图片}")
@RequestMapping("/admin")
@RestController
public class PhotoController {


    @Autowired
    private PhotoService photoService;

    @SystemLog(notes = "获取图片列表{后台管理系统}")
    @ApiOperation(value = "获取图片列表接口",notes = "根据条件 获取图片列表")
    @GetMapping("/photos")
    public ResponseResult getPhotos(@RequestParam("current") Integer current,
                                    @RequestParam("size") Integer size,
                                    @RequestParam(value = "albumId",required = false) Integer albumId,
                                    @RequestParam("isDelete") Integer isDelete){
        return photoService.getPhotoList(current,size,albumId,isDelete);
    }

    @SystemLog(notes = "添加图片数据{后台管理系统}")
    @ApiOperation(value = "添加图片数据接口")
    @PostMapping("/photos")
    public ResponseResult addPhotos(@RequestBody PhotoAddDTO photoAddDTO){
        return photoService.addPhotos(photoAddDTO);
    }

    @SystemLog(notes = "更新图片信息{后台管理系统}")
    @ApiOperation(value = "更新图片信息接口")
    @PutMapping("/photos")
    public ResponseResult updatePhoto(@RequestBody Photo photo){
        return photoService.updatePhoto(photo);
    }

    @SystemLog(notes = "逻辑删除图片{后台管理系统}")
    @ApiOperation(value = "逻辑删除图片接口",notes = "根据图片ID 逻辑删除图片{非真正删除}")
    @PutMapping("/photos/delete")
    public ResponseResult delPhotoByLogic(@RequestBody ReceptionParam receptionParam){
        return photoService.delPhotoByLogic(receptionParam);
    }

    @SystemLog(notes = "删除图片{后台管理系统}")
    @ApiOperation(value = "删除图片接口",notes = "根据图片ID 删除图片{真正删除}")
    @DeleteMapping("/photos")
    public ResponseResult delPhotos(@RequestBody Integer[] idList){
        return photoService.delPhotos(idList);
    }


}
